package cn.funeralobjects.ams.web.mapper;

import cn.funeralobjects.ams.entity.EProductRes;
import cn.funeralobjects.ams.model.ProductRes;
import cn.funeralobjects.ams.web.model.MProductRes;
import cn.funeralobjects.ams.web.model.VProductRes;
import cn.funeralobjects.common.web.controller.converter.ModelMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * @author FuneralObjects
 * Create date: 2020/5/26 10:31 AM
 */
@Mapper(componentModel = "spring", uses = {RegionMapper.class, ProductMapper.class, AccessMapper.class})
public interface ProductResMapper extends ModelMapper<MProductRes, ProductRes, EProductRes, VProductRes> {

    /**
     * entity -> vo
     *
     * @param eProductRes entity
     * @return vo
     */
    @Mappings({
            @Mapping(target = "productId", source = "product.id"),
            @Mapping(target = "regionId", source = "region.id"),
    })
    @Override
    VProductRes toVo(EProductRes eProductRes);

    /**
     * vo -> entity
     *
     * @param vProductRes vo
     * @return entity
     */
    @Mappings({
            @Mapping(target = "product.id", source = "productId"),
            @Mapping(target = "region.id", source = "regionId"),
    })
    @Override
    EProductRes toEntity(VProductRes vProductRes);
}
